<template>
  <div class="sidebar">
    <div class="logo-container">
      <div class="logo">
        <span class="logo-icon">🧑‍💻</span>
        <span class="logo-text">金融工具平台</span>
      </div>
    </div>
    
    <el-menu 
      :default-active="route.path === '/' ? '/welcome' : route.path"
      class="el-menu-vertical" 
      @select="handleSelect" 
      router
      :collapse="isCollapsed"
    >
      <el-menu-item index="/welcome">
        <i class="el-icon-home"></i>
        <span>首页</span>
      </el-menu-item>      
      <el-menu-item index="/loan-calculator">
        <i class="el-icon-money"></i>
        <span>贷款计算器</span>
      </el-menu-item>      
      <el-menu-item index="/stock-valuation">
        <i class="el-icon-data-line"></i>
        <span>现金流估值</span>
      </el-menu-item>      
      <el-menu-item index="/ai-chat">
        <i class="el-icon-robot"></i>
        <span>AI问答</span>
      </el-menu-item>
      <el-menu-item index="/post-integrated">
        <i class="el-icon-chat"></i>
        <span>发帖讨论</span>
      </el-menu-item>
    </el-menu>
    
    <div class="collapse-btn" @click="toggleCollapse">
      <i :class="isCollapsed ? 'el-icon-right' : 'el-icon-left'"></i>
    </div>
  </div>
</template>


<script setup>
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()
const isCollapsed = ref(false)

function handleSelect(index) {
  router.push(index)
}

function toggleCollapse() {
  isCollapsed.value = !isCollapsed.value
}
</script>

<style scoped>
.sidebar {
  display: flex;
  flex-direction: column;
  background-color: var(--secondary-light);
  border-right: 1px solid var(--secondary-color);
  position: relative;
  transition: all 0.3s;
  z-index: 10;
}

.logo-container {
  padding: 1.5rem 1rem;
  border-bottom: 1px solid var(--secondary-color);
  background: var(--gradient-green);
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-icon {
  font-size: 1.5rem;
  margin-right: 0.5rem;
  color: white;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 600;
  color: rgb(48, 31, 31);
}

.el-menu-vertical {
  border-right: none !important;
  flex: 1;
  background-color: var(--secondary-light);
}

.el-menu-vertical:not(.el-menu--collapse) {
  width: 220px;
}

/* 调整菜单项垂直间距 */
:deep(.el-menu-item) {
  height: 50px;
  line-height: 50px;
  font-size: 1rem;
  border-left: 3px solid transparent;
  transition: all 0.3s;
  color: var(--neutral-700);
}

/* 菜单图标 */
:deep(.el-menu-item i) {
  color: var(--secondary-dark);
  margin-right: 0.5rem;
  font-size: 1.25rem;
}

/* 鼠标悬停和选中状态 */
:deep(.el-menu-item:hover) {
  background-color: rgba(255, 255, 255, 0.8);
  color: var(--secondary-dark);
}

:deep(.el-menu-item.is-active) {
  background-color: rgba(0, 209, 178, 0.15);
  color: var(--secondary-dark);
  border-left: 3px solid var(--secondary-dark);
  font-weight: 600;
}

:deep(.el-menu-item.is-active i) {
  color: var(--secondary-dark);
}

.collapse-btn {
  position: absolute;
  bottom: 20px;
  right: -12px;
  width: 24px;
  height: 24px;
  background: var(--gradient-green);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

/* 为菜单图标添加样式 */
.el-icon-home::before { content: "🏠"; }
.el-icon-chat::before { content: "💬"; }
.el-icon-star::before { content: "⭐"; }
.el-icon-money::before { content: "💰"; }
.el-icon-data-line::before { content: "📈"; }
.el-icon-robot::before { content: "🤖"; }
.el-icon-left::before { content: "◀"; }
.el-icon-right::before { content: "▶"; }

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
  }
  
  .el-menu-vertical:not(.el-menu--collapse) {
    width: 100%;
  }
  
  .collapse-btn {
    display: none;
  }
}
</style>